package cn.zswltech.gruul.common.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
public class DisplayGroupDO {
    private String icon;
    private String groupName;
    private Long groupId;
    private String code;
    private String enName;
    private Date gmtCreate;
    private Integer sortNo;
    private Long parentId;
    private List<JSONObject> children;

    private String menuName;
    private Long menuId;
    private String path;
    private String target;
    private JSONArray functionList;
    private JSONObject function;

    public void setOneLevelMenu(){
        if (CollectionUtils.isNotEmpty(children) && children.size() == 1){
            JSONObject jsonObject = children.get(0);
            String type = jsonObject.getString("type");
            if ("1".equals(type)) {
                setCode(jsonObject.getString("code"));
                setEnName(jsonObject.getString("enName"));
                setMenuName(jsonObject.getString("menuName"));
                setMenuId(jsonObject.getLong("menuId"));
                setPath(jsonObject.getString("path"));
                setTarget(jsonObject.getString("target"));
                setFunctionList(jsonObject.getJSONArray("functionList"));
                setFunction(jsonObject.getJSONObject("function"));
                setGroupName(null);
                setChildren(null);
            }
        }
    }
}
